/*
 * @Descripttion:
 * @version:
 * @Author: zlh
 * @Date: 2021-11-23 16:00:28
 * @LastEditors: zlh
 * @LastEditTime: 2021-11-23 17:59:19
 */
export const dragable = () => {

  let modal = document.getElementsByClassName("ant-modal");
  let header = document.getElementsByClassName("ant-modal-header");

  //给box1绑定按下事件
  header.forEach((item, index) => {
    item.onmousedown = function(event) {
      //获取相对偏移量
      const relLeft = event.clientX - parseInt(window.getComputedStyle(modal[index], null).left);
      const relTop = event.clientY - parseInt(window.getComputedStyle(modal[index], null).top);
  
      //当鼠标移动时，box1跟着移动，需要绑定给document元素
      document.onmousemove = function(event) {
        //解决兼容性问题
        event = event || window.event;
  
        //获取鼠标的坐标
        const left = event.clientX;
        const top = event.clientY;
  
        //将坐标赋值给box1
        modal[index].style.left = left - relLeft + "px";
        modal[index].style.top = top - relTop + "px";
      };
  
      //给box1绑定鼠标松事件
      document.onmouseup = function() {
        //让box1停止移动
        //取消跟随鼠标移动事件
        document.onmousemove = null;
  
        //取消此事件
        document.onmouseup = null;
      };
    };
  });
};
